---------------------------------------------------------------- PID Controller VBX Control Copyright 1993 Northeast Data Corp. All Rights Reserved THIS IS THE DEMONSTRATION VERSION OF THE CONTROL The control functions in the same manner as the commercial version, except that a registration dialog box appears each time the control is accessed. To eliminate this nuisance, register the control with Northeast Data Corp. ---------------------------------------------------------------- Release 1.0 August 1993 This document describes the PID Controller Custom VBX Control. CONTENTS 1. Product Description 2. Legal Information 3. Installation 4. Usage 5. Support ---------------------------------------------------------------- 1. Product Description The PID Controller VBX Control is a Microsoft Windows DLL designed and implemented in compliance with Microsoft standards for interfacing with Visual Basic. The control functions like a standard Proportional-Integral-Derivative controller used in industrial plants. It can be used for modeling chemical processing equipment and other kinds of plant installations that use closed-loop feedback control. See appendix A for a simple introduction to process control. To the application programmer, the interface to the slider is similar to the other MS Windows controls, with a few special messages added for performing operations specific to the PID control. Being a VBX control, the programmer can add the PID Control to the tool palette in Visual Basic. This allows use of the control in Visual Basic forms. Since Visual C++ supports use of VBX controls, the slider control can also be used in the Visual C++ environment. Use of the PID Controller in a finished VB or Visual C++ application requires the PID Control DLL (pid.vbx) to be installed with the application. This is true of all custom controls written for MS Windows. There are properties available that allow the programmer to control the behavior and appearance of the Control. All communication between the PID Control and the application is performed using the standard Windows message mechanism for controls. Design of the PID Control message mechanism allows the application to continuously monitor the settings of the control. ------------------------------------------------------------------- 2. Legal Information The purchaser of the PID Control is allowed to use it and distribute it in applications without paying any royalty, and without printing or displaying a copyright notice for the control. This only includes distribution of the PID Control DLL (PID.VBX). It does not include distribution of documentation that comes with the Control. The purchaser of the PID Control may distribute the control DLL with applications that are networked (multiple users accessing the DLL from a file server) without paying any license fees to Northeast Data Corp. ------------------------------------------------------------------- 3. Installation Create a "PID" directory on your hard disk and copy all files from the distribution disk to the directory. You should copy the pid.vbx file to your Windows\System directory. Start Visual Basic or the Visual C++ App Studio applications and use the custom control installation function to install the pid.vbx control. ------------------------------------------------------------------- 4. Usage PROPERTIES ---------- Action - Stop, Run, Reset. Reset causes all values stored in the controller to be reset to their controller startup settings. BackColor - Sets the background color. DragIcon - Name of the icon that will appear when the control is dragged. DragMode - Normal or automatic. Gain - The sensitivity of the controller. This value is multiplied times the difference between the setpoint and measured value, then divided by difference between the maximum and minimum control values (the range of the controller). The value is expressed as a percentage, so 100 will cause a 50% output when the difference between measured value and setpoint is 1 half of the span of the controller (100 degrees). Height - Height of control. Index - Index of control. Left - Left position. Measured - Position of the measured value arrow. Mode - Manual or Automatic. If set to automatic, the controller calculates and sets the output value based on the measured value and setpoint. If set to manual, the controller does not adjust the output, but allows you to set it manually. Setting the mode to manual also allows you to write your own algorithms for controlling the output based on the measured value and setpoint. MVColor - Color of the measured value arrow. MVTickColor - Color of the tick marks on the measured value scale. Name - Standard property for the name of the control. OPColor - Color of the output arrow. OPMode - Normal or Reverse. In reverse mode the output is set to 100% when the measured value is greater than the setpoint. In normal mode, the output is zero when the measured value is over the setpoint. This is useful for controlled devices that work in opposite fashions. For example, some pneumatic valves are closed at 100% output and wide open at 0% output. Other valves are the opposite of this. OPTickColor - Color of the tick marks on the output scale. Output - Position of the output arrow on the output scale. This can only be set if the Mode property is set to Manual. Poll - Controller update period (in seconds). This value should be set to something reasonable (a few seconds). Setting it too low will cause the control to take a large amount of CPU time. Preact - This value determines how many minutes the controller "looks ahead" to determine how the output should be adjusted. The calculation is done by extrapolating from the previous measured value to determine what the value will be at the specified lead time. This setting affects the ability of the controller to respond ahead of time to rapid changes in the measured value. Reset - The number of times per minute that the normal output calculated based on the Gain is reapplied to the output. This setting affects the ability of the controller to correct for a continuous offset between the setpoint and measured value. SetPoint - Current setpoint position. This must be a value between or including the current minimum and maximum values of the controller. SPColor - Color of the setpoint arrow. SPMax - Maximum control value. This must be greater than the minimum value. This established the maximum value for the setpoint and measured values. SPMin - Minimum control value. This must be less than the maximum value. This establishes the minimum value for the setpoint and measured values of the controller. SPTickColor - Color of the tick marks on the setpoint scale. TabIndex - Control tab order. TabStop - If this is turned on (1 instead of 0), the PID controller can be activated by tabbing to it with the TAB key. Tag - Control tag. Top - Top of control window. Visible - Visible/Invisible attribute. Width - Width of control. EVENTS ------ These events work the same way as for other VBX controls. DblClick DragDrop DragOver GotFocus KeyDown KeyUp LostFocus Measured Output Setpoint In order to update values in your application based on the current position of the PID control, you should handle the Output and Setpoint events. The measured value event is not usually needed, since it is your application that sets the measured value based on the controller output. The setpoint event will occur when the user drags the setpoint arrow in the controller. ----------------------------------------------------------------------- 5. Support You don't get any until you register. APPENDIX A - Process Control Overview There are many books available on process control theory. You can find them at any good technical library. Process control is a complex field of study - far too broad to cover in detail in this document. The following covers some of the basics to get you started. A lot can be learned just by "playing" with the PID VBX control. It is possible to connect your PC to laboratory equipment through a special analog adapter and perform real process control, using the PID control in Visual Basic or Visual C++ to perform the control calculations and output. Process control is divided into two broad categories; "Open Loop" and "Closed Loop". Open loop controllers send an output signal (air pressure or electrical) to a pneumatic valve or electronic solenoid. The level of the output signal is adjusted with no knowledge of conditions at the point of control. For example, a steam valve could be set to 50% of it's travel. The kettle of water being heated is at some unknown temperature and heats up as steam is fed to it. The temperature of the water rises continuously to some point of equilibrium. No change occurs to the steam valve setting unless the operator manually adjusts the output to the valve. This type of control is manual. Closed loop control is a technique for automatically adjusting valve or other component settings based on the measured value of the material being controlled. For example, placing a thermocouple in the kettle of water and feeding the measured temperature back to the controller allows the controller to determine a new setting for the steam valve. In closed loop control, the tricky part is coming up with an algorithm that determines the best setting for the valve or other device based on the measured input. It's tricky because of the large number of physical characteristics of the plant that affect the behavior of the measured feedback signal and the signal going out to the valve. Various things cause time delays in the sensing of input values and adjustment of output devices. Since there are usually more complex things to control than a kettle of water, the nature of the fluid or whatever is being controlled various widely. For example, typical chemical reactions cause enormous perturbations in the stability of the system (the extreme case being an explosion). Modern control theory attempts to quantify all these factors and produce optimum control algorithms. PROPORTIONAL CONTROL ==================== The simplest form of closed-loop control is "Proportional". The output signal is determined by the difference between the setpoint and the measured value in relation to the range of the controller. A multiplier (called the "Gain") is used to determine the new output value. The output is calculated as: setpoint - measured value ------------------------- * (gain/100) max output - min output A gain of 100% means, for example, a setpoint of 75 degrees and a current water temperature of 50 degrees results in an output of 25% (where the output ranges from zero to 100% of the valve range). A gain of 2 would cause an output of 50%. This assumes the span of the controller (range of measured value and setpoint) is 100. This type of control is adequate for some systems. Industrial controls implement this type of control (as well as all those described in this document) by pneumatic elements using air pressure or by electrical components using electrical sensors and solenoids. The PID VBX control implements control by running a timer that periodically reads properties set by the application (the key one being the measured value). The timer period can be set using the "Poll" property. RESET CONTROL (Integral) ============= Then things get a little trickier. What if 25% output is not enough to heat the water (or whatever) above 50 degrees? The controller is now at equilibrium; no further changes in water temperature will occur. The system operates at a steady offset between the setpoint and the measured value. Usually, this is not quite what is desired. The operator can correct the condition by manually setting the setpoint to 100 degrees, hoping that the controller will settle down with an offset of 25 degrees, leaving the water temperature at the desired 75 degrees. Depending on the system behavior, this may not happen. The operator may have to "play" with the setpoint to find the setting that works. The next type of control operation attempts to correct this problem. It does, in effect, what the operator would have to do manually. That is, it resets the effective setpoint when it sees that the measured value does not come up to the setpoint over some period of time. This element of control operation is called, appropriately "Automatic Reset", or just "Reset". The numeric value for the reset is the number of times per minute that the controller adds the output calculated from the simple gain to the current output value. The output is adjusted rather than the setpoint - the effect is the same, and is preferable to putting the setpoint to a location that looks strange to the operator. The effect of reset is to, over time, eliminate the offset between the setpoint and the measured value. The disadvantage to this technique is that reset tends to desensify the controller. That is, once the setpoint has been reached, the reset may have driven the output so high that the measured value "overshoots" the setpoint. Also, if the controller is left in operation (doing calculations) while active components of the system are turned off, the reset component will build up a large output value. When the components are turned on, the controller massively overshoots the setpoint. For example, if a manual steam valve is turned off while the controller is running, reset will eventually drive the output to 100% because the measured value never comes up to the setpoint (no steam available). When the manual valve is opened, the reset component takes no effect until the measured value has reached the setpoint. By the time the controller has determined there is no continuing offset, the measured value has overshot the setpoint by a large value. This phenomenon is sometimes called "Reset Windup". This problem can be overcome to some extent by providing a switch to turn the controller on and off. While the system is not being used, the controller is turned off. These prevents the reset component from building up incorrect output values. The VBX control contains an Action property for turning the controller on and off and for resetting it, which zeroes out all retained calculations. Reset control action is also known as "Integral" control, since controller output is determined by integrating offsets over a period of time. DERIVATIVE CONTROL (Preact) ================== Many systems have lengthy delays between the sensing of temperatures or other parameters and transmission of these to the controller. There can also be extensive delays in the transmission and use of output signals from the controller. The effect of these problems is that the new adjustment at the point of control is incorrect by the time it arrives. This problem is evident in all controls by observing a phenomenon known as "Cycling", where the measured value repeatedly overshoots and undershoots the setpoint. A controller operating in this condition is said to be "hunting". There are also process events that "surprise" the controller. A chemical reaction typically produces these at the time the chemicals begin to react. Sensitive proportional control can somewhat compensate for this problem, but Reset control tends to make things worse if the reaction occurs when the measured value is below the setpoint, since Reset will continue to boost the output until the measured value is above the setpoint. Derivative control looks at the difference between the previous measured value and the current one. It calculates a counter-output to be applied to the proportional output. In effect, it guesses what the next measured value will be based on the slope (hence the term "Derivative") of the measured value and generates an output to "get ahead" of the process. Derivative control is also known as "Preact". The numeric value for the preact is the number of minutes to look ahead to calculate the output. For example: If the previous measured value was 45 degrees and occured 10 seconds ago If the current measured value was 50 degrees and the Preact value is .5 The rate of change in measured value is 30 degrees per minute. The preact value indicates we should use the measured value .5 minutes in the future. Based on the rate of change, the measured value will be 65 degrees in .5 minutes ( 50 (current value) + 30 (deg/min ) / .5 (min) ). The preact component will calculate an output based on 65 degrees, whereas the proportional component will base its calculation on 50 degrees. The outputs calculated by proportional, integral, and derivative components are added together to form the new output value. TUNING ====== The business of setting optimum values for Gain, Reset, and Preact is known as "Tuning" the controller. This is typically done through trial and error. Although there are many algorithms used for calculating these settings, many process systems are so complex that the trial-and-error technique is the most effective. Controllers can become more complex by "cascading" them. In this configuration, the output from one controller is used to set the setpoint of another controller. Two controllers cascaded is the norm, but there is no technical limit. Tuning these types of controllers is usually done by tuning the controller closest to the process (called the "slave") first, and tuning the "master". APPENDIX B - Example Visual Basic Application ========== The application provided with the PID control is a simple example of controlling a kettle of water (or whatever). The application sets the measured value based on the output of the control and the current temperature of the water. Edit boxes let you play with the Gain, Reset, and Preact. Buttons let you stop, start, and reset the controller. Three graph controls are used to chart the setpoint, measured value, and output. The game here is to try your hand at tuning the controller. You can test your skill by making controller settings and adjustments to the setpoint. The goal is to tune the controller for optimum measured value control. You need to minimize cycling, offsets, and overshoots. You can change the behavior of the system by modifying the algorithms for calculation of the measured value. You may want to add an "Explosion" button or something like that to give a sudden burst in measured value to see how your controller responds. If you have better ideas for controlling a process, set the mode of the controller to "Manual" and write your own subroutine for calculating the output based on the measured value and setpoint. This, in effect, lets you design your own industrial controller. You can add all kinds of logic for dealing with special behavior of your process. For example, you may know that your chemical reaction "takes off" at exactly 14 minutes after the temperature reaches a setpoint of 67 degrees. Your algorithm could make adjustments to setpoint, set the controller and let your algorithm "take over", or make adjustments to the gain, reset, and preact. This is pretty cool, since many industrial controllers don't have nearly this much flexibility. It's also fun to hook up the MCI control and play wave files for special effects when certain things happen in the controlled process. Enjoy.